var prefix = "/jzweb/bookOrder";
$(function(){
	//学校查询
	$('#school').selectPage({
		showField: 'name',
		keyField: 'name',
		data: prefix+'/selectSchool',
		//向服务端提交的参数中，增加已选中的
		//设置返回-1，意为通知服务端返回空列表，初始化时使用
		params: function(){
			var pv = $('#school').val();
			return pv;
		},
		eAjaxSuccess : function(d){
			var result;
			if(d) result = d.data;
			else result = undefined;
			return result;add.js
		}
	});

});




$().ready(function() {
	validateRule();

});

$.validator.setDefaults({
	submitHandler : function() {
		save();
	}
});
function save() {
	$.ajax({
		cache : true,
		type : "POST",
		url : "/jzweb/bookOrder/save1",
		data : $('#signupForm').serialize(),// 你的formid
		async : false,
		error : function(request) {
			parent.layer.alert("Connection error");
		},
		success : function(data) {
			if (data.code == 0) {
				parent.layer.msg("操作成功");
				parent.reLoad();
				var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
				parent.layer.close(index);

			} else {
				parent.layer.alert(data.msg)
			}

		}
	});

}
layui.use('upload', function () {
	var upload = layui.upload;
	//执行实例
	upload.render({
		elem: '#btnUploadOrder', //绑定元素
		url: '/common/sysFile/upload', //上传接口
		accept: 'file',
		done: function (r) {
			$("#exlUrl").val(r.data);
			$("#test").html(subFileName(r.data));
		},
		error: function (r) {
			layer.msg(r.msg);
		}
	});
});
function validateRule() {
	var icon = "<i class='fa fa-times-circle'></i> ";
	$("#signupForm").validate({
		rules : {
			bookId : {
				required : true
			},
			orderNumber : {
				required : true
			},
			orderPrimary : {
				required : true
			},
			orderIntermediate : {
				required : true
			},
			discount : {
				required : true
			},
			province : {
				required : true
			},
			orderSenior : {
				required : true
			},
			address : {
				required : true
			},
			school : {
				required : true
			},
			year : {
				required : true
			},
			addressee : {
				required : true
			}

		},
		messages : {
			bookId : {
				required : icon + "请选择对应书籍种类"
			},
			orderNumber : {
				required : icon + "请输入理论订单数量"
			},
			orderPrimary : {
				required : icon + "请输入理论初级数量"
			},
			orderIntermediate : {
				required : icon + "请输入理论中级数量"
			},
			orderSenior : {
				required : icon + "请输入理论高级数量"
			},
			discount : {
				required : icon + "请输入折扣价"
			},
			province : {
				required : icon + "请输入省份"
			},
			address : {
				required : icon + "请输入详细地址"
			},
			school : {
				required : icon + "请输入单位名称或学校名称"
			},
			year : {
				required : icon + "年份必须填写"
			},
			addressee : {
				required : icon + "请输入收件人"
			}

		}
	})
}